package com.奇技淫巧;


import cn.hutool.json.JSONObject;
import com.wedata.HttpUtils;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class BankCard {

    public static void busiAccount(String[] args) {
        String host = "https://busiacct.market.alicloudapi.com/lundear/busiAccount";
        String method = "GET";
        String appcode = "4c2fc9f7f64b43009f95884135a62f25";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("account", "866188198510661");
        querys.put("acctName", "北京小度网络科技有限公司");
        querys.put("bankName", "招商银行股份有限公司北京大屯路支行");
        System.out.println(new JSONObject(querys));
        if("".equals("")){
            return;
        }
        String params = "?account=866188198510661&acctName=北京小度网络科技有限公司&bankName=招商银行股份有限公司北京大屯路支行";

        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            JSONObject response = HttpUtils.doGet(host+params, headers);
            System.out.println(response);
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
            //{"code":0,"desc":"信息一致","transamt":"7","tradeNo":"1654919423198","abstract":"账户验证:1234"}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void bankArea(String[] args) {
        String host = "https://bkarea.market.alicloudapi.com/lundear/bankArea?cardno=6214830100960565";
        String method = "GET";
        String appcode = "4c2fc9f7f64b43009f95884135a62f25";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("cardno", "6214830100960565");


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            JSONObject response = HttpUtils.doGet(host, headers);
            System.out.println(response);
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
            //{"data":{"bankCode":"308584000013","cardBin":"621483","abbr":"CMB","cardName":"银联IC普卡","bankLogo":"http://img.lundear.com/e4aa64.png","area":"北京市 - 北京市","binLen":6,"bankId":"03080000","cardType":"借记卡","bankPhone":"95555","bankName":"招商银行","bankUrl":"https://www.cmbchina.com"},"desc":"成功","code":0}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 银行【支行】联行号查询
     */
    public static void main(String[] args) {
        String host = "https://qrybkcode.market.alicloudapi.com/lundear/qrylhh?cardno=6230200095629288&city=深圳市";
        String method = "GET";
        String appcode = "4c2fc9f7f64b43009f95884135a62f25";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("cardno", "6214830100960565");
        //{"totalpage":187,"code":0,"page":1,"desc":"成功","data":[{"bank":"招商银行","bankCode":"308100005019","abbr":"CMB","addr":"北京市西城区复兴门内大街156号","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-66426889","lName":"招商银行股份有限公司北京分行"},{"bank":"招商银行","bankCode":"308100005027","abbr":"CMB","addr":"北京市国际企业金融大厦A座北京市复兴门内大街156号","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-66426622;010-66427121","lName":"招商银行股份有限公司北京分行营业部"},{"bank":"招商银行","bankCode":"308100005035","abbr":"CMB","addr":"北京市海淀区中关村南大街2号数码大厦A座双安商场西侧","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-52786212;010-52786220","lName":"招商银行股份有限公司北京中关村支行"},{"bank":"招商银行","bankCode":"308100005043","abbr":"CMB","addr":"北京市东城区东总布胡同58号天润财富中心1楼","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-65292021;010-65292027","lName":"招商银行股份有限公司北京长安街支行"},{"bank":"招商银行","bankCode":"308100005051","abbr":"CMB","addr":"北京市西城区车公庄大街21号院1号楼1层","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-68365421;010-68365433","lName":"招商银行股份有限公司北京甘家口支行"},{"bank":"招商银行","bankCode":"308100005060","abbr":"CMB","addr":"北京市朝阳区北辰东路8号北京国际会议中心B1层","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-84987347;010-84987476","lName":"招商银行股份有限公司北京亚运村支行"},{"bank":"招商银行","bankCode":"308100005078","abbr":"CMB","addr":"北京市朝阳区东三环北路6号楼一层103室及二层201室","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-64628774","lName":"招商银行股份有限公司北京东三环支行"},{"bank":"招商银行","bankCode":"308100005086","abbr":"CMB","addr":"北京市海淀区白石桥路7号理工科技大厦一层","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-68467184","lName":"招商银行股份有限公司北京双榆树支行"},{"bank":"招商银行","bankCode":"308100005094","abbr":"CMB","addr":"北京市海淀区万寿路西街2号文博大厦一层(长安街路南)","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-68286557;010-68286582","lName":"招商银行股份有限公司北京万寿路支行"},{"bank":"招商银行","bankCode":"308100005109","abbr":"CMB","addr":"北京市朝阳区工人体育场北路甲2号盈科中心A栋1层底商","bankLogo":"http://img.lundear.com/e4aa64.png","city":"北京市","province":"北京市","tel":"010-65272070;010-65272067","lName":"招商银行股份有限公司北京三里屯支行"}]}

        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            JSONObject response = HttpUtils.doGet(host, headers);
            System.out.println(response);
            //{"data":{"bank":"招商银行","bankCode":"308121000024","abbr":"CMB","addr":"河北省石家庄市长安区中山东路303号(博物院地铁站B东南口步行150米)","bankLogo":"http://img.lundear.com/e4aa64.png","city":"石家庄市","province":"河北省","tel":"0311-67802088","lName":"招商银行股份有限公司石家庄广安支行"},"desc":"成功","code":0}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
     * 银行支行
     */
    public static void main2(String[] args) {
        String host = "https://qrybkcode.market.alicloudapi.com/lundear/qryshh?bankcode=308100005086";
        String method = "GET";
        String appcode = "4c2fc9f7f64b43009f95884135a62f25";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("cardno", "6214830100960565");


        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            JSONObject response = HttpUtils.doGet(host, headers);
            System.out.println(response);
            //{"data":{"bank":"招商银行","bankCode":"308121000024","abbr":"CMB","addr":"河北省石家庄市长安区中山东路303号(博物院地铁站B东南口步行150米)","bankLogo":"http://img.lundear.com/e4aa64.png","city":"石家庄市","province":"河北省","tel":"0311-67802088","lName":"招商银行股份有限公司石家庄广安支行"},"desc":"成功","code":0}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     *
     * @param args
     */
    public static void bcheck(String[] args) {
        StringBuffer host = new StringBuffer("https://zball.market.alicloudapi.com/v2/bcheck");
        String appcode = "4c2fc9f7f64b43009f95884135a62f25";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("accountNo", "621226110200xxxxx");
        querys.put("name", "张三");
        //querys.put("idCardCode", "130321198804010xxx");
        //querys.put("bankPreMobile", "1860017xxx");

        host.append("?");
        if(querys != null){
            final Set<String> keySet = querys.keySet();
            int size = keySet.size();
            for(String key : keySet) {
                host.append(key).append("=").append(querys.get(key));
                size--;
                if(size!=0){
                    host.append("&");
                }
            }
        }

        System.out.println(host.toString());
        try {
            /**
             * 重要提示如下:
             * HttpUtils请从
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
             * 下载
             *
             * 相应的依赖请参照
             * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
             */
            JSONObject response = HttpUtils.doGet(host.toString(), headers);
            System.out.println(response);
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
